<?php
//require section
require_once dirname(__FILE__) . '/shared/config/config.php';
require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_security.php';
$title = 'Đăng Kí';




?>

<!DOCTYPE html>
<html>
    <head>
        <?php
        require_once DOCUMENT_ROOT . DIR_INCLUDE . 'head.php';
        ?>
    </head>
    <body>
        <?php

        $email = "";
        $password = "";
        $password_confirm = "";
        $first_name = "";
        $last_name = "";
        $address = "";
        $phone = "";
        if (!empty($_POST)) {
            if (!empty($_POST['txt_first_name'])) {
                $first_name = $_POST['txt_first_name'];
            }
            if (!empty($_POST['txt_last_name'])) {
                $last_name = $_POST['txt_last_name'];
            }
            if (!empty($_POST['txt_address'])) {
                $address = $_POST['txt_address'];
            }
            if (!empty($_POST['txt_phone'])) {
                $phone = $_POST['txt_phone'];
            }
            if (!empty($_POST['txt_email'])) {
                $email = $_POST['txt_email'];
            }
            if (!empty($_POST['txt_password'])) {
                $password = $_POST['txt_password'];
            }
            if (!empty($_POST['txt_password_confirm'])) {
                $password_confirm = $_POST['txt_password_confirm'];
            }
            $error_show = api_security::validate_user_info($email, $password,
                    $password_confirm, $first_name, $last_name, $address, $phone);
            if (empty($error_show)) {
                if (api_security::register($email, $password, $first_name, $last_name, $address, $phone)) {
                    $success_info = "Chúc mừng, bạn đã là thành viên.";
                    $email = "";
                    $password = "";
                    $password_confirm = "";
                    $first_name = "";
                    $last_name = "";
                    $address = "";
                    $phone = "";
                }
            } else {
                $password = "";
                $password_confirm = "";
            }
        }
        ?>
        <div class="uk-container uk-container-center uk-margin-top">
            <?php
            require_once DOCUMENT_ROOT . DIR_INCLUDE . 'menu.php';
            require_once DOCUMENT_ROOT . DIR_INCLUDE . 'slider.php';
            ?>

            <!-- Changable content -->
            <section id="main-content" class="ts-body-container uk-panel uk-panel-box ts-padding-large">
                <article class="uk-article">
                    <h1 class="uk-article-title ts-color-primary">Đăng Kí Thành Viên</h1>
                    <hr class="uk-article-divider">
                    <div>
                        <form name="form_data" id="form_data" class="uk-form" method="POST" enctype="multipart/form-data" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">

                            <!-- Hidden Value Section -->

                            <!-- End Hidden Value Section -->
                            <?php
                            if (!empty($error_show)) {?>
                            <div class="error">Lỗi: <?php echo $error_show; ?></div>
                            <?php
                            } else if (!empty($success_info)) {?>
                            <div class="success"><?php echo $success_info; ?></div>
                            <?php
                            }?>

                            <table class="ts-table">
                                <tr>
                                    <th><label for="txt_first_name">Họ:<span class="ts-alert">*</span></label></th>
                                    <td><input name="txt_first_name" class="uk-form-width-large" value="<?php echo $first_name; ?>" type="text" placeholder="Họ" required></td>
                                </tr>
                                <tr>
                                    <th><label for="txt_last_name">Tên:<span class="ts-alert">*</span></label></th>
                                    <td><input name="txt_last_name" class="uk-form-width-large" value="<?php echo $last_name; ?>" type="text" placeholder="Tên" required></td>
                                </tr>
                                <tr>
                                    <th><label for="txt_address">Địa Chỉ:<span class="ts-alert">*</span></label></th>
                                    <td><input name="txt_address" class="uk-form-width-large" value="<?php echo $address; ?>" type="text" placeholder="Địa chỉ" required></td>
                                </tr>
                                <tr>
                                    <th><label for="txt_phone">Số Điện Thoại:<span class="ts-alert">*</span></label></th>
                                    <td><input name="txt_phone" class="uk-form-width-large" value="<?php echo $phone; ?>" type="text" placeholder="Số điện thoại" required></td>
                                </tr>
                                <tr>
                                    <th><label for="txt_email">Email:<span class="ts-alert">*</span></label></th>
                                    <td><input name="txt_email" class="uk-form-width-large" value="<?php echo $email; ?>" type="text" placeholder="Email" required></td>
                                </tr>
                                <tr>
                                    <th><label for="txt_password">Mật Mã:<span class="ts-alert">*</span></label></th>
                                    <td><input name="txt_password" class="uk-form-width-large" value="<?php echo $password; ?>" type="password" placeholder="Mật mã" required></td>
                                </tr>
                                <tr>
                                    <th><label for="txt_password_confirm">Xác Nhận Mật Mã:<span class="ts-alert">*</span></label></th>
                                    <td><input name="txt_password_confirm" class="uk-form-width-large" value="<?php echo $password_confirm; ?>" type="password" placeholder="Xác nhận mật mã" required></td>
                                </tr>
                                <tr>
                                    <th></th>
                                    <td><input type="submit" name="btn_submit" value="Đăng Kí" class="uk-button uk-button-large uk-button-primary"></td>
                                </tr>
                            </table>
                        </form>
                    </div>
                </article>
            </section>
            <!-- End changable content -->

            <?php
            require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php';
            ?>
        </div>
    </body>
</html>